/* CodeBuilder代码生成器 生成时间：2011-11-07 23:26:00 */
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Comm;
using System.Collections;

public partial class Web_Admin_SpaceCode_SpaceCode_List : AdminPageBase
{
    private List<Model.Classification> typelist = null;
    private BLL.SpaceCode bll = new BLL.SpaceCode();
    protected void Page_Load(object sender, EventArgs e)
    {
        base.CheckPopedomInfoRedirect(1026, 1);
        But_Delete.Visible = base.CheckPopedomInfo(1026, 8);
        if (!IsPostBack)
        {
            loadData();
        }   
    }

    /// <summary>
    /// 获取类型名称
    /// </summary>
    /// <param name="obj"></param>
    protected string getClassificationName(object obj)
    {
        if (obj == null || obj.ToString() == "")
        {
            return "";
        }
        if (typelist == null)
        {
            typelist = new BLL.Classification().DataTableToList(new BLL.Classification().GetList(0, "", "Ordinal asc").Tables[0]);
        }

        string typename = "";
        foreach (string id in obj.ToString().Split(','))
        {
            if (!string.IsNullOrEmpty(id))
            {
                Model.Classification model = typelist.Find(delegate(Model.Classification item) { return item.ID.Value == int.Parse(id); });
                if (model != null)
                {
                    typename += model.ClassName + ",";
                }
            }
        }

        return System.Text.RegularExpressions.Regex.Replace(typename, ",$", "");
    }

    /// <summary>
    /// 获取条件
    /// </summary>
    /// <returns></returns>
    private string getStrWhere()
    {
        string strWhere = "";
        strWhere = System.Text.RegularExpressions.Regex.Replace(strWhere, "^ and", "");

        return strWhere;
    }

    /// <summary>
    /// 获取排序
    /// </summary>
    /// <returns></returns>
    private string getSort()
    {
        string sort = "";

        return sort;
    }

    /// <summary>
    /// 加载数据
    /// </summary>
    private void loadData()
    {
        Model.PageData data = bll.GetList(AppClass.PageSize, base.PageIndex, getStrWhere(), getSort());
        rpList.DataSource = data.DataSoure;
        rpList.DataBind();
        pgServer.RecordCount = data.Count;
        pgServer.PageSize = AppClass.PageSize;
        pgServer.DataBind();
        lit_nodata.Visible = data.Count < 1 ? true : false;
    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void But_Delete_Click(object sender, EventArgs e)
    {
        string ids = Request.Form["checkboxs"];
        if (string.IsNullOrEmpty(ids))
        {
            return;
        }

        bll.DeleteList("ID in ("+ids+")");
        base.AddLog(3, "空间代码管理ID:" + ids);
        loadData();
    }


    /// <summary>
    /// 导出
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void But_Excel_Click(object sender, EventArgs e)
    {
        string[] fileName = { "ID","UserID","Classification","Content","UpNum","DownNum","AddTime","Lang" };
        string[] title = { "ID","UserID","Classification","Content","UpNum","DownNum","AddTime","Lang" };
        DataToExcel.Export(fileName, title, "TB_SpaceCode", "空间代码列表_" + DateTime.Now.ToString("yyy-MM-dd"), getStrWhere(), getSort());
    }
}
